package com.qzing.apijson.dcp.edu.controller;

import apijson.RequestMethod;
import apijson.framework.APIJSONController;
import apijson.orm.Parser;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @ClassName EduController
 * @Description 教育信息接口
 * @Author liucs
 * @Date 2021-03-29
 * @Version V1.0
 */
@RestController
@RequestMapping("/edu")
@Slf4j
public class EduController extends APIJSONController {
    private static final String TAG = "EduController";

    /**
     * 关闭校验
     * @param session
     * @param method
     * @return
     */
    @Override
    public Parser<Long> newParser(HttpSession session, RequestMethod method) {
        return super.newParser(session, method).setNeedVerify(false);
    }

    @GetMapping("/hello")
    public String sayApiJson(){
        System.out.println("hi apiJson");
        return "API JSON SO EASY";
    }

    /**
     * 新增学生
     * @param request
     * @param session
     * @return
     */
    @PostMapping("/add")
    @Override
    public String post(@RequestBody String request, HttpSession session) {
        System.out.println("request:"+request);
        return super.post(request, session);
    }

    /**
     * 修改学生信息
     * @param request
     * @param session
     * @return
     */
    @PostMapping("/put")
    @Override
    public String put(@RequestBody String request, HttpSession session) {
        return super.put(request, session);
    }

    /**
     *  查询班级学生列表
     * @param classId 班级Id
     * @return list 学生列表
     */
    @PostMapping("/get/students")
    public String getStudents(@RequestBody String classId,HttpSession session){

        String students = super.get(classId, session);
        log.info("get Stus:{}",students);
        return students;
    }

    @PostMapping("/get/studs")
    public String getStudents(@RequestBody Map<String,String> paramMap, HttpSession session){
        String classId=paramMap.get("classId");
        String model=paramMap.get("Student");
        if (classId!=null){
            log.info("get classId:{}",classId);
        }
        String request= JSONObject.toJSONString(paramMap);
        log.info("request:{}",request);
        String students = super.get(request, session);
        log.info("get Stus:{}",students);
        return students;
    }
}
